import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from "@tarojs/components"
import { getFoodCount, setFoodCount } from "../../../../utils/common.js"
import './addcut.scss'
class Addcut extends Component {
  constructor() {
    super(...arguments);
    this.state = {
      num: 1
    }
  }
  CutFood() {
    if (this.props.foodList) {
      if (this.state.num > 0) {
        setFoodCount(this.props.foodList, this.state.num, "cut", () => {
          this.setState({ Num: getFoodCount(this.props.foodList) })
        })
      } else {
        console.log("数据异常")
      }
    }
  }
  AddFood() {
    if (this.state.num > 0) {
      setFoodCount(this.props.foodList, this.state.num, "add", () => {
        console.log(123213)
        this.setState({ Num: getFoodCount(this.props.foodList) })
      })
    }
  }
  componentDidMount() {
    // this.setState({ Num: getFoodCount(this.props.foodList) })
  }
  render() {
    let { num } = this.state;
    let hideClass = num > 0 ? "num" : "hide"
    return (
      <View className="addcut">
        <Image onClick={this.CutFood.bind(this)} className="operate_img" src={require('../../../../assets/img/cut.png')} />
        <Text className={hideClass}>{num}</Text>
        <Image onClick={this.AddFood.bind(this)} className="operate_img" src={require('../../../../assets/img/add.png')} />
      </View>
    )
  }
}
export default Addcut